% Rudimentary Plain TeX referencing scheme for the manual.

\newcount\refnum
\newif\iffoundref

\def\lrefs{}

\newtoks\ta
\newtoks\tb

{\catcode`\_=11

\gdef\ismember#1\of#2{\foundreffalse
	\refnum=0
	\def\given{#1}%
	\def\\##1{\advance\refnum by1%
	\def\next{##1}\ifx\next\given
		\foundreftrue
	\fi}%
	#2}

\gdef\testref#1{%
	\ismember#1\of\lrefs
	\iffoundref\else
		\ta={\\#1}%
		\tb=\expandafter{\lrefs}%
		\xdef\lrefs{\the\tb\the\ta}%
		\advance\refnum by1%
	\fi
	}

\gdef\cite#1{{%
	\edef\next{\noexpand\testref{\expandafter\noexpand
\csname r_#1\endcsname}}\next
	\refcite}}

\gdef\refcite{~[\the\refnum]}

\gdef\dref#1#2\par{\edef\next{\gdef\csname r_#1\endcsname{#2}}%
	\next}

\gdef\manrefs{{\refnum=0
	\def\\{\advance\refnum by1%
	\xdef\cur_ref{\the\refnum}%
	\medskip
	\refcite\ignorespaces\ }\lrefs}}
}

